import { store } from "@/store"
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { showError } from '@/utils/msg-show'
import { getDefRateApi } from '@/api/sys/defRate'

export const useDefaultRateStore = defineStore("DefaultRate", () => {

	const isZero = ref(true)
    const retaForm = reactive<any>({
			rechargeSingle: null,
			rechargeRate: null,
			withdrawSingle: null,
			withdrawRate: null
	})
  
	/** 获取默认费率 */
	async function getDefRate(){
		await getDefRateApi().then((res: any) => {
			Object.assign(retaForm, res.data)
		}).catch(err => {
			showError(err.msg || err.errMsg || err)
		})
	}

	/** 初始化 */
	async function init() {
		if (isZero.value) {
            await getDefRate()
			isZero.value = false
		}
	}

   
	return {
		init, 
        retaForm,
	}

})

export function useDefaultRateStoreHook() {
	return useDefaultRateStore(store);
}